import http from '@utils/request'
import { UsernameRequest, PhonecodeForm, PhoneRuleForm } from '@interface/login'
// 图形验证码
export const captchaImage = (params: { key: string }): Promise<ArrayBuffer> => {
  return http({
    url: '/captcha/image',
    // arraybuffer 一定是小写
    responseType: 'arraybuffer',
    params
  })
}

//用户登录模块
export const LoginJson = (data): Promise<UsernameRequest> => {
  return http({
    url: '/u/loginByJson',
    method: 'post',
    data
  })
}

// 获取动态验证码
export const LoginYzm = (data: PhonecodeForm): Promise<UsernameRequest | null> => {
  return http({
    url: '/captcha/sendRegisterOrLoginCaptcha',
    method: 'get',
    params: data
  })
}

//手机号验证码登录
export const LoginByMobile = (data: PhoneRuleForm): Promise<UsernameRequest> => {
  return http({
    url: '/u/loginByMobile',
    method: 'post',
    data
  })
}
